package com.xxx.client.android.api.util;

import java.util.Hashtable;
import java.util.LinkedList;

public class RequestCache {

	private static int CACHE_LIMIT = 10;

	private LinkedList<String> history;
	private Hashtable<String, Object> cache;

	public RequestCache() {
		history = new LinkedList<String>();
		cache = new Hashtable<String, Object>();
	}

	public void put(String url, Object data) {
		history.add(url);
		// too much in the cache, we need to clear something
		if (history.size() > CACHE_LIMIT) {
			String old_url = (String) history.poll();
			cache.remove(old_url);
		}
		cache.put(url, data);
	}

	public Object get(String url) {
		return cache.get(url);
	}

	public void clearCache() {
		cache.clear();
	}

	public void clearCache(String url) {
		cache.remove(url);
	}
}
